// 监听是否登录
import {csrf} from "./utils/index.js";
import router from "./router/index.js";
import {useStore} from "./store/index.js";
const showControl = ['/mobile-details-song']

const redirection = ['/user/my-message', '/user/my-setting']
router.beforeEach(((to, from, next) => {
  const store = useStore()
  // 判断是否存在token
  if (store.token) {
    // 从cookie中获取csrf_token
    csrf(store.token)
    // 判断是否存在userinfo
    if (Object.keys(store.userInfo).length) {
    } else {
      // 如果不存在用户信息就获取用户信息
      store.getLoginStatus()
    }
  } else {
   if (redirection.indexOf(to.matched[2]?.path) !== -1) {
     next('/')
     return
   }
  }
  // noPlayerControl作用如果页面进入了移动端歌曲详情，就不展示次控件
  store.noPlayerControl = showControl.indexOf(to.path) !== -1;
  // 进入Mv页面不展示播放控件
  store.noShowMvPlayCon = to.path !== '/mv';
  next()
}))